/*
ID: khymill1
PROG: stamps
LANG: C++
*/
#include <string.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
#include <limits>
using namespace std;


int main()
{
    ifstream fin("stamps.in");
    ofstream fout("stamps.out");
    int k, n;
    fin >> k >> n;
    vector<int> stamps(n, 0);
    int maxVal = 0;
    for (int i = 0; i < n; i++) {
        fin >> stamps[i];
        maxVal = max(maxVal, stamps[i]);
    }
    sort(stamps.begin(), stamps.end());
    if (stamps[0] != 1) {
        //cout << 0 << endl;
        return 0;
    }
    vector<bool> dp(maxVal*k+1, false);
    vector<int> needCoins(maxVal*k+1, 0);
    dp[1] = true;
    for (int i = 1; i <= k; i++) {
       dp[maxVal*i] = true; 
       needCoins[maxVal*i] = i;
    }
    needCoins[1] = 1;
    for (int i = 2; i <= maxVal*k; i++) {
        bool done = false;
        int minCoins = 10000;
        for (int j = max(1, i - maxVal); j < i && !done; j++) {
           if (dp[j] == true && needCoins[j] < k) {
                for (int k = stamps.size()-1; k >=0; k--) {
                    if (stamps[k] == i) {
                        dp[i] = true;
                        minCoins = 1;
                        done = true;
                    }
                    if (j + stamps[k] == i) {
                        dp[i] = true;
                        minCoins = min(minCoins, needCoins[j]) + 1;
                        done = true;
                    }
                }
           }
        }
        needCoins[i] = minCoins;
         //cout << " --- " << needCoins[i]  << " " <<  i << endl;
        if (!done) {
            fout << i-1 << endl;
            break;
        }
    }
    return 0;
}                                          
